package com.ideafactory.client.utils;

import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;

import com.ideafactory.client.utils.caches.CacheUtils;
import com.ideafactory.client.ybservice.APP;

import java.util.UUID;

/**
 * Created by LiuShao on 2016/4/11.
 */

public class DeviceUtils {

    public  static String getMacAddress() {
        String macAddress = null;
        WifiManager wifiManager = (WifiManager) APP.getAPP().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = (null == wifiManager ? null : wifiManager.getConnectionInfo());

        if (!wifiManager.isWifiEnabled()) {
            //必须先打开，才能获取到MAC地址
            wifiManager.setWifiEnabled(true);
//            wifiManager.setWifiEnabled(false);
        }

        if (null != info) {
            macAddress = info.getMacAddress();
        }

        if (macAddress != null) {
            String mac = macAddress.toUpperCase();
            String macS = "";
            for (int i=mac.length()-1;i>=0;i--) {
                macS += mac.charAt(i);
            }
            UUID uuid2 = new UUID(macS.hashCode(), mac.hashCode());

            CacheUtils.setDeviceNo(uuid2.toString());

            return uuid2.toString();
        } else {
            return "-1";
        }
    }




}
